const btn = this.getApiPage().getApiWidgetByAliasName('detail-judge')
btn.hideWidget()
const ico = this.getApiPage().getApiWidgetByAliasName('judge-ico')
ico.hideWidget()
const confirm = this.getApiPage().getApiWidgetByAliasName('confirm')
confirm.showWidget()
const save = this.getApiPage().getApiWidgetByAliasName('detail-save')
save.showWidget()
const cancel = this.getApiPage().getApiWidgetByAliasName('cancel-event');
cancel.showWidget()
const cancelIcon = this.getApiPage().getApiWidgetByAliasName('取消图标');
cancelIcon.showWidget()

const form = this.getApiPage().retrievePlugin('base-forms')
const data = form.getFormData('form_20')
const obj = Object.keys(data).reduce((acc, key) => {
  if (data[key] !== '') {
    acc[key] = data[key];
  }
  return acc;
}, {});


const $form = this.getApiPage().getApiWidgetByAliasName('judge-content').widgetObj;
// 详情时隐藏上传显示
$form._option.config.forEach(v => {
  if (v.type == 'upload') {
    v.visible = false
  }

  if (v.dataIndex == 'sourceDeviceId') {
    v.visible = false
  }
})
console.log('$form', $form)
$form._option.isDetail = false
$form.render()
form.setFormData('form_20', $form._option.dataSource)


const options = {
  method: 'GET',
  headers: {
    "Content-type": "application/json",
  }
}
fetch(`/Basics/basics-main/system/equipmentObject/listDetailByEquipmentCode?equipmentTypeCode=camera&areaId=${$form.areaId}`, options)
  .then(res => res.json())
  .then(json => {
    if (json?.resultCode === '000000') {
      json.result.rows.forEach(i => {
        i.name = i.equipmentName;
        i.value = i.equipmentCode;
      });
      $form.asyncSelectOptions('sourceDeviceId', json.result.rows);
      $form.tempData = json.result.rows;
      form.setFormData('form_20', {
        sourceDeviceId: $form._option.dataSource.sourceDeviceId
      })
    }
  })

///////////////////////////////////////////////////////////////////////////////

this.getApiPage().getApiWidgetByAliasName('confirm')?.showWidget()
this.getApiPage().getApiWidgetByAliasName('detail-save')?.showWidget()
this.getApiPage().getApiWidgetByAliasName('cancel-event')?.showWidget()
this.getApiPage().getApiWidgetByAliasName('取消图标')?.showWidget()

const form = this.getApiPage().retrievePlugin('base-forms')
const data = form.getFormData('form_20')
const obj = Object.keys(data).reduce((acc, key) => {
  if (data[key] !== '') acc[key] = data[key];
  return acc;
}, {});

const $form = this.getApiPage().getApiWidgetByAliasName('judge-content').widgetObj;
// 详情时隐藏上传显示
$form._option.config.forEach(v => {
  v.visible = !(v.type == 'upload' || v.dataIndex == 'sourceDeviceId')
})

console.log('$form', $form)
$form._option.isDetail = false
$form.render()
form.setFormData('form_20', $form._option.dataSource)

this.widgetObj?.queryDeviceList($form.areaId).then(result => {
  if (result) {
    $form.asyncSelectOptions('sourceDeviceId', result.rows);
    $form.tempData = result.rows;
    form.setFormData('form_20', {
      sourceDeviceId: $form._option.dataSource.sourceDeviceId
    })
  }
})

